﻿

$('.service > table').hide();

$('#li-air').click(function() {
    $('#table-air').slideToggle('slow');
});


$('#li-insurance').click(function () {
    $('#table-insurance').slideToggle('slow');
});

$('#li-commission').click(function () {
    $('#table-commission').slideToggle('slow');
});

$('#li-visa').click(function () {
    $('#table-visa').slideToggle('slow');
});
$('#li-travel-guide').click(function () {
    $('#table-travel-guide').slideToggle('slow');
});
$('#li-land-tour').click(function () {
    $('#table-land-tour').slideToggle('slow');
});
$('#li-calculator').click(function () {
    $('.table-calculator').slideToggle('slow');
});

    
    
var totalPriceAdults = 0;
var totalPriceChild = 0;
var totalPriceBaby = 0;
var totalPriceVat = 0;
var totalPrice = 0;


TotalPriceAdults = function () {
    var priceAirAdults = parseInt($("#TotalTicketAirPricesAdults").html());
    var priceTravelGuideAdults = parseInt($("#TotalTravelGuidePricesAdults").html());
    var priceCommissionAdults = parseInt($("#TotalHHAdults").html());
    var priceInsuranceAdults = parseInt($("#TotalInsurancePricesAdults").html());
    var priceVisaAdults = parseInt($("#TotalVisaAdults").html());
    var priceLandTourAdults = parseInt($("#TotalLandTourPricesAdults").html());

    totalPriceAdults = priceAirAdults + priceTravelGuideAdults + priceCommissionAdults +
        priceInsuranceAdults + priceVisaAdults + priceLandTourAdults;
    $("#TotalPriceCaculatorAdults").html(totalPriceAdults);
};
TotalPriceChild = function () {
    var priceAirChild = parseInt($("#TotalTicketAirPricesChild").html());
 
    var priceTravelGuideChild = parseInt($("#TotalTravelGuidePricesChild").html());
    var priceCommissionChild = parseInt($("#TotalHHChild").html());
    var priceInsuranceChild = parseInt($("#TotalInsurancePricesChild").html());
    var priceVisaChild = parseInt($("#TotalVisaChild").html());
    var priceLandTourChild = parseInt($("#TotalLandTourPricesChild").html());

    totalPriceChild = priceAirChild + priceTravelGuideChild + priceCommissionChild +
        priceInsuranceChild + priceVisaChild + priceLandTourChild;
    $("#TotalPriceCaculatorChild").html(totalPriceChild);
};
TotalPriceBaby = function () {
    var priceAirBaby = parseInt($("#TotalTicketAirPricesBaby").html());
    var priceCommissionBaby = parseInt($("#TotalHHBaby").html());
    var priceInsuranceBaby = parseInt($("#TotalInsurancePricesBaby").html());
    var priceVisaBaby = parseInt($("#TotalVisaBaby").html());
    var priceLandTourBaby = parseInt($("#TotalLandTourPricesBaby").html());


    totalPriceBaby = priceAirBaby + priceCommissionBaby + priceInsuranceBaby + priceVisaBaby +  priceLandTourBaby;
    $("#TotalPriceCaculatorBaby").html(totalPriceBaby);

};

TotalPriceVat = function () {
    var priceAirVat = parseInt($("#TotalVatAir").html());
    var priceCommissionVat = parseInt($("#TotalVatCommission").html());
    var priceInsuranceVat = parseInt($("#TotalVatInsurance").html());
    var priceVisaVat = parseInt($("#TotalVatVisa").html());
    var priceTravelGuideVat = parseInt($("#TotalVatTravelGuide").html());
    var priceLandTourVat = parseInt($("#TotalVatLandTour").html());
   
    totalPriceVat = priceAirVat  + priceCommissionVat + priceInsuranceVat + priceVisaVat +
         priceTravelGuideVat + priceLandTourVat;
    $("#TotalVatCaculator").html(totalPriceVat);

};
//TotalPrice = function (quantityAdults, quantityChild, quantityBaby) {
TotalPrice = function () {
    TotalPriceAdults();
    TotalPriceChild();
    TotalPriceBaby();
    TotalPriceVat();
    //var totalPriceCaculator = totalPriceAdults * quantityAdults + totalPriceChild * quantityChild + totalPriceBaby * quantityBaby;
    //$("#TotalPriceCaculator").html(totalPriceCaculator);
    var priceAir = parseInt($("#TotalTicketAirPrices").html());
    var priceTravelGuide = parseInt($("#TotalTravelGuidePrices").html());
    var priceCommission = parseInt($("#TotalHHPrices").html());
    var priceInsurance = parseInt($("#TotalInsurancePrices").html());
    var priceVisa = parseInt($("#TotalVisaPrices").html());
    var priceLandTour = parseInt($("#TotalLandTourPrices").html());
    
    totalPrice = priceAir  + priceTravelGuide + priceCommission +
        priceInsurance + priceVisa + priceLandTour;
    $("#TotalPriceCaculator").html(totalPrice);

};
TotalSalePriceCalculator = function (salePriceAdultsElement, salePriceChildElement, salePariceBabyElement,
            totalSalePriceElement, priceOnCustomerElement, quantityAdults, quantityChild, quantityBaby) {
    //ham tinh tong gia ban doan

    var salePriceAdults = $(salePriceAdultsElement).val();
    var salePriceChild = $(salePriceChildElement).val();
    var salePriceBaby = $(salePariceBabyElement).val();
    var totalSalePrice = $(totalSalePriceElement).val();
    var priceOnCustomer = $(priceOnCustomerElement).val();

    var saleAdults = 0;
    var saleChild = 0;
    var saleBaby = 0;
    var totalSale = 0;
    var totalVat = 0;
    var chiPhiQuanLy = 0;
    var thueThuNhap = 0;
    var vatChenhLech = 0;
    var laiRongDoan = 0;

    var profitAdults = 0;
    var profitChild = 0;
    var profitBaby = 0;
    var profit = 0;

    if (priceOnCustomer > 0) {
        chiPhiQuanLy = priceOnCustomer * (parseInt(quantityAdults) + parseInt(quantityChild) + parseInt(quantityBaby));
    }
    if (salePriceAdults > 0 && salePriceAdults < 100) {
        saleAdults = totalPriceAdults + totalPriceAdults * (salePriceAdults / 100);
        profitAdults = totalPriceAdults * (salePriceAdults / 100);
    }
    if (salePriceChild > 0 && salePriceChild < 100) {
        saleChild = totalPriceChild + totalPriceChild * (salePriceChild / 100);
        profitChild = totalPriceChild * (salePriceChild / 100);
    }
    if (salePriceBaby > 0 && salePriceBaby < 100) {
        saleBaby = totalPriceBaby + totalPriceBaby * (salePriceBaby / 100);
        profitBaby = totalPriceBaby * (salePriceBaby / 100);
    }
    if (totalSalePrice > 0 && totalSalePrice < 100) {
        totalSale = totalPrice + totalPrice * (totalSalePrice / 100);
        profit = totalPrice * (totalSalePrice / 100);
        totalVat = totalSale * 0.1;
        vatChenhLech = totalVat - totalPriceVat;
    }
    if (profit > chiPhiQuanLy) {
        thueThuNhap = (profit - chiPhiQuanLy) * 0.23;
        laiRongDoan = profit - chiPhiQuanLy - thueThuNhap;
    }

    $('#TotalSaleCaculatorAdults').html(saleAdults);
    $('#TotalSaleCaculatorChild').html(saleChild);
    $('#TotalSaleCaculatorBaby').html(saleBaby);
    $('#TotalSaleCaculator').html(totalSale);
    $('#TotalSaleVatCaculator').html(totalVat);

    $('#ProfitCaculatorAdults').html(profitAdults);
    $('#ProfitCaculatorChild').html(profitChild);
    $('#ProfitCaculatorBaby').html(profitBaby);
    $('#ProfitCaculator').html(profit);

    $('#ChenhLechVat').html(vatChenhLech);
    $('#ChiPhiQuanLy').html(chiPhiQuanLy);
    $('#ThueThuNhap').html(thueThuNhap);
    $('#LaiRongDoan').html(laiRongDoan);

};
    
ProfitCalculator = function (percentAdultsElement, percentChildElement, percentBabyElement, percentTotalElement, priceOnCustomerElement, note1Element, note2Element, note3Element, note4Element, note5Element, note6Element, note7Element, note8Element, note9Element, note10Element, note11Element, note12Element, note13Element, note14Element, note15Element, note16Element, tourId, profitCalculatorId) {
    var fncInsertProfitCalculator = function () {
        var percentAdults = $(percentAdultsElement).val();
        if (percentAdults < 0 || percentAdults > 100 || percentAdults == "") { percentAdults = 0; }
        var percentChild = $(percentChildElement).val();
        if (percentChild < 0 || percentChild > 100 || percentChild == "") { percentChild = 0; }
        var percentBaby = $(percentBabyElement).val();
        if (percentBaby < 0 || percentBaby > 100 || percentBaby == "") { percentBaby = 0; }
        var percentTotal = $(percentTotalElement).val();
        if (percentTotal < 0 || percentTotal > 100 || percentTotal == "") { percentTotal = 0; }
        var priceOnCustomer = $(priceOnCustomerElement).val();
        if (priceOnCustomer < 0 || priceOnCustomer == "") { priceOnCustomer = 0; }
        var note1 = $(note1Element).val();
        var note2 = $(note2Element).val();
        var note3 = $(note3Element).val();
        var note4 = $(note4Element).val();
        var note5 = $(note5Element).val();
        var note6 = $(note6Element).val();
        var note7 = $(note7Element).val();
        var note8 = $(note8Element).val();
        var note9 = $(note9Element).val();
        var note10 = $(note10Element).val();
        var note11 = $(note11Element).val();
        var note12 = $(note12Element).val();
        var note13 = $(note13Element).val();
        var note14 = $(note14Element).val();
        var note15 = $(note15Element).val();
        var note16 = $(note16Element).val();

        $.ajax({
            type: "POST",
            url: "/ajax_vmh.html",
            data: {
                "function": "InsertProfitCalculator", 'profitCalculatorId': profitCalculatorId, "tourId": tourId, 'percentAdults': percentAdults, 'percentChild': percentChild,
                'percentBaby': percentBaby, 'percentTotal': percentTotal, 'priceOnCustomer': priceOnCustomer, 'note1': note1,
                'note2': note2, 'note3': note3, 'note4': note4, 'note5': note5, 'note6': note6, 'note7': note7, 'note8': note8,
                'note9': note9, 'note10': note10, 'note11': note11, 'note12': note12, 'note13': note13, 'note14': note14, 'note15': note15, 'note16': note16
            },
            dataType: "json",
            success: function (data) {


            }

        });
        hidePopup('profit-note1');
        hidePopup('profit-note2');
        hidePopup('profit-note3');
        hidePopup('profit-note4');
        hidePopup('profit-note5');
        hidePopup('profit-note6');
        hidePopup('profit-note7');
        hidePopup('profit-note8');
        hidePopup('profit-note9');
        hidePopup('profit-note10');
        hidePopup('profit-note11');
        hidePopup('profit-note12');
        hidePopup('profit-note13');
        hidePopup('profit-note14');
        hidePopup('profit-note15');
        hidePopup('profit-note16');
    };

    $('.btnInsertProfitNote').click(fncInsertProfitCalculator);
    $(percentAdultsElement).change(fncInsertProfitCalculator);
    $(percentChildElement).change(fncInsertProfitCalculator);
    $(percentBabyElement).change(fncInsertProfitCalculator);
    $(percentTotalElement).change(fncInsertProfitCalculator);
    $(priceOnCustomerElement).change(fncInsertProfitCalculator);
};